package com.xiaoyu.lanling.feature.login.controller

import `in`.srain.cube.request.JsonData
import android.content.Context
import com.xiaoyu.base.data.UserData
import com.xiaoyu.base.data.UserDataLifecycleListener
import com.xiaoyu.base.utils.MMKVUtil
import com.xiaoyu.lanling.common.Constant
import com.xiaoyu.lanling.feature.user.model.UserExtra

class UserDataLifecycleListenerImpl : UserDataLifecycleListener {

    override fun afterLogin(jsonData: JsonData) {
        MMKVUtil.get(UserData.getInstance().uid).putBoolean(Constant.MMKVKey.KEY_HAS_PROFILE, jsonData.optBoolean("hasSetProfile"))
        UserExtra.instance.restore(jsonData.optJson("user"))
    }

    override fun afterLogout() {
    }

    override fun initiateSync(context: Context?) {
    }

    override fun initiateAsync(context: Context, userExtraJson: JsonData) {
        super.initiateAsync(context, userExtraJson)
        UserExtra.instance.restore(userExtraJson)
    }

    override fun initiateAsync(context: Context?) {
    }

    override fun initiateSyncInMultiProcess() {
    }
}